DAY12:Complementary DNA


Posted by birdbirdmurmur on 2023-07-25

題目連結:

Complementary DNA

解法:

function DNAStrand(dna){
  return dna.replace(/[ACTG]/g, match =>{
    switch(match){
      case "A":
        return "T";
      case "T":
        return "A";
      case "C":
        return "G";
      case "G":
        return "C";
    }
  })
}

筆記:

替換字先想到replace()
/[ATCG]/g:找到所有A、T、C、G四個字母
switch()將傳遞進來的值通過case轉換成另外一個字


#javascript #Codewars #replace #switch







Related Posts

模組化與 Library

模組化與 Library

用 Nest.js 開發 API 吧 (一)

用 Nest.js 開發 API 吧 (一)

Robot Framework之安裝教學

Robot Framework之安裝教學


Comments